$data.Entity.extend('Theme', {
	id: { type: 'int', key: true, required: true },	
	titre: { type: 'string',required: true },
	theme_parent: { type: 'int'}
});

function getValueThemes(BD,champs,valeur){
	return BD.Themes.filter('it.'+champs+' == '+valeur).toArray();
}

function getValueThemesAndQcm(BD,champs,valeur){

	return $.when(BD.Themes.filter('it.'+champs+' == '+valeur).toArray()).then(function(themes){
		var listeQcms = [];		
		var listeThemes = [];	
		
		themes.forEach(function(theme){
			listeQcms.push(getValueQcms(BD,'theme_id',theme.id));			
			listeThemes.push(theme);			
		});
		
		if(listeThemes.length == 0){			
			return listeThemes;
		}
		
		return $.when.apply(this, listeQcms).then(function(){
			
			for( var i = 0; i < arguments.length; i++ ) {	
				listeThemes[i].qcms =  arguments[i];
			}

			return listeThemes;
		});

	});
	
}